import { useSelector } from "react-redux";
import { RootState } from "../..";
import { useMemo } from "react";

export const useNodeMap = (nodeId?: string | null | undefined) => {

    const boxDataStore = useSelector((state: RootState) => state.reactDnd.boxData);
    const boxIndexStore = useSelector((state: RootState) => state.reactDnd.boxIndex);
    const lastHoverDataStore = useSelector((state: RootState) => state.reactDnd.lastHoverData);
    const boxData = useMemo(() => {
        const map = new Map();
        Object.values(boxDataStore).forEach(container => {
            map.set(container.id, {
                ...container,
            });
        });
        return map
    }, [boxDataStore])
    const boxIndex = useMemo(() => {
        return boxIndexStore
    }, [boxIndexStore])
    return {
        boxData,
        boxIndex,
        lastHoverDataStore,
    };
}